package com.ali.config;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 自定义异常处理器
 */
public class MyExceptionHandler {
    /**
     * 异常处理
     */
    public static String exceptionHandle(Exception exception) {
        String result;

        StringWriter stringWriter = null;
        PrintWriter printWriter = null;
        try {
            stringWriter = new StringWriter();
            printWriter = new PrintWriter(stringWriter);
            exception.printStackTrace(printWriter);
            result = stringWriter.toString();
        } finally {
            if (stringWriter != null) {
                try {
                    stringWriter.close();
                } catch (IOException e) {
                    e.fillInStackTrace();
                }
            }
            if (printWriter != null) {
                printWriter.close();
            }
        }

        return result;
    }
}